package com.sqlweb.sqlweb.base;

import org.rosuda.REngine.Rserve.*;

public class CATClient {
    public static void main(String[] args) throws RserveException {
        try {
            // 连接到 Rserve
            RConnection r = new RConnection();

            // 用户答题过程
            int examineeID = 1; // 用户 ID
            int itemID = 1;     // 当前题目 ID
            int response = 1;   // 用户回答

            // 调用 R 函数处理新答题
            r.eval(String.format("handleNewItemResponse(%d, %d, %d)", examineeID, itemID, response));

            // 获取当前能力值估计
            double thetaCurrent = (Double) r.eval(String.format("calculateTheta(%d)", examineeID)).asDouble();
            System.out.println("当前能力值估计: " + thetaCurrent);

            // 关闭连接
            r.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}